package com.ruoyi.web.controller.ydz;

import java.util.List;

import com.ruoyi.web.domain.OtherNews;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.domain.NewsTdk;
import com.ruoyi.web.service.INewsTdkService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 新闻tdk配置Controller
 * 
 * @author drx
 * @date 2024-03-21
 */
@Controller
@RequestMapping({"/ydz/newsTdk","/api/newsTdk"})
@Api(tags = "新闻tdk配置")
public class NewsTdkController extends BaseController
{
    private String prefix = "ydz/tdk";

    @Autowired
    private INewsTdkService newsTdkService;

    @RequiresPermissions("ydz:tdk:view")
    @GetMapping()
    public String tdk()
    {
        return prefix + "/tdk";
    }

    /**
     * 查询新闻tdk配置列表
     */
    @RequiresPermissions("ydz:tdk:list")
    @PostMapping("/list")
    @ResponseBody
    @ApiOperation("查询新闻tdk配置列表")
    public TableDataInfo list(NewsTdk newsTdk)
    {
        startPage();
        List<NewsTdk> list = newsTdkService.selectNewsTdkList(newsTdk);
        return getDataTable(list);
    }

    /**
     * 导出新闻tdk配置列表
     */
    @RequiresPermissions("ydz:tdk:export")
    @Log(title = "新闻tdk配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    @ApiOperation("导出新闻tdk配置列表")
    public AjaxResult export(NewsTdk newsTdk)
    {
        List<NewsTdk> list = newsTdkService.selectNewsTdkList(newsTdk);
        ExcelUtil<NewsTdk> util = new ExcelUtil<NewsTdk>(NewsTdk.class);
        return util.exportExcel(list, "新闻tdk配置数据");
    }

    /**
     * 新增新闻tdk配置
     */
    @GetMapping("/add")
    @ApiOperation("新增新闻tdk配置")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存新闻tdk配置
     */
    @ApiOperation("新增保存新闻tdk配置")
    @RequiresPermissions("ydz:tdk:add")
    @Log(title = "新闻tdk配置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(NewsTdk newsTdk)
    {
        return toAjax(newsTdkService.insertNewsTdk(newsTdk));
    }

    /**
     * 修改新闻tdk配置
     */
    @ApiOperation("修改新闻tdk配置")
    @RequiresPermissions("ydz:tdk:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        NewsTdk newsTdk = newsTdkService.selectNewsTdkById(id);
        mmap.put("newsTdk", newsTdk);
        return prefix + "/edit";
    }

    /**
     * 根据id查询tdk配置
     */
    @ApiOperation("根据id查询tdk配置")
    @GetMapping("/get/{id}")
    @ResponseBody
    public NewsTdk getTdk(@PathVariable("id") Long id)
    {
        NewsTdk newsTdk = newsTdkService.selectNewsTdkById(id);
        return newsTdk;
    }

    /**
     * 修改保存新闻tdk配置
     */
    @ApiOperation("修改保存新闻tdk配置")
    @RequiresPermissions("ydz:tdk:edit")
    @Log(title = "新闻tdk配置", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(NewsTdk newsTdk)
    {
        return toAjax(newsTdkService.updateNewsTdk(newsTdk));
    }

    /**
     * 删除新闻tdk配置
     */
    @ApiOperation("删除新闻tdk配置")
    @RequiresPermissions("ydz:tdk:remove")
    @Log(title = "新闻tdk配置", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(newsTdkService.deleteNewsTdkByIds(ids));
    }


    /**
     * 修改保存新闻管理
     */
    @ApiOperation("修改保存新闻管理")
    @RequiresPermissions("ydz:otherNews:edit")
    @Log(title = "新闻管理", businessType = BusinessType.UPDATE)
    @PostMapping("/editNewsSet")
    @ResponseBody
    public AjaxResult editNewsSet(@RequestBody List<NewsTdk> list)
    {
        return newsTdkService.editNewsSet(list);
    }
}
